package plus.easydo.easypush.service.impl;

import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import plus.easydo.easypush.cache.ChannelCache;
import plus.easydo.easypush.dingtalk.DingTalkConst;
import plus.easydo.easypush.dingtalk.service.DingTalkService;
import plus.easydo.easypush.entity.ChannelInfo;
import plus.easydo.easypush.service.PushServer;

/**
 * @author laoyu
 * @version 1.0
 * @date 2022/2/26
 */
@Service
public class PushServerImpl implements PushServer {

    @Autowired
    DingTalkService dingTalkService;

    @Autowired
    ChannelCache channelCache;

    @Override
    public Boolean push(String secret, String channelId, String title, String text) throws ApiException {
        ChannelInfo channel = channelCache.getChannelBySecretAndAndChannelId(secret, channelId);
        switch (channel.getChannelType()){
            case DingTalkConst.CHANNEL_TYPE:
                return dingTalkService.pushText(channel,title,text);
            default:
                return false;
        }
    }
}
